package com.ads.tpgrupo4.server.service.nuevaOrdenDePedido;

import com.ads.tpgrupo4.domain.cpr.ordenDePedido.OrdenDePedido;
import com.ads.tpgrupo4.server.remote.PersistenceService;
import com.ads.tpgrupo4.server.xml.XmlSource;
import com.ads.tpgrupo4.server.xml.mappers.OrdenDePedidoXmlMapper;

public class NuevaOrdenDePedidoService {

	private static NuevaOrdenDePedidoService instance;

	private PersistenceService persistenceService = PersistenceService
			.getInstance();

	private OrdenDePedidoXmlMapper ordenDePedidoXmlMapper = OrdenDePedidoXmlMapper
			.getInstance();

	public static NuevaOrdenDePedidoService getInstance() {

		if (instance == null) {
			instance = new NuevaOrdenDePedidoService();
		}

		return instance;
	}

	private NuevaOrdenDePedidoService() {
	}

	public void nuevaOrdenDePedido(final XmlSource nuevaOrdenDePedidoXmlSource) {

		try {

			final OrdenDePedido ordenDePedido = this.ordenDePedidoXmlMapper
					.map(nuevaOrdenDePedidoXmlSource);

			this.persistenceService.saveOrdenDePedido(ordenDePedido);

		} catch (final Exception e) {
			throw new NuevaOrdenDePedidoServiceException(e);
		}
	}

}
